package com.crawler.dto;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ProcessingTime {
    private int defaultYear = 0;// 默认年
    private int defaultMonth = 0;// 默认月
    private int firstMonth = 0;// 第一航段月份

    public ProcessingTime(String scheduledTime) {
        defaultYear = Integer.parseInt(scheduledTime.substring(0, scheduledTime.indexOf("年")));
        defaultMonth = Integer.parseInt(scheduledTime.substring(scheduledTime.indexOf("年") + 1,
                scheduledTime.indexOf("月")));
    }

    public String getDate(String date) {
        int year = defaultYear, month = Integer.parseInt(date.substring(0, date.indexOf("月")));
        if (firstMonth == 0) {
            if (month < defaultMonth)
                year = defaultYear + 1;
            firstMonth = month;
        } else {
            if (month < defaultMonth)
                year = defaultYear + 1;
        }
        return year + "年" + date;
    }
    
    /**
     * 
     * 方法描述：比较日期 是否超出当前时间  
     * @author TL  
     * @date 2016年6月20日 下午9:10:37  
     * @param date
     * @return
     * @throws ParseException
     */
    public boolean comparingDate(String date) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        if (new Date().getTime() >= format.parse(getDate(date)).getTime())
            return true;
        return false;
    }

    @Override
    public String toString() {
        return "ProcessingTime [defaultYear=" + defaultYear + ", defaultMonth=" + defaultMonth + ", firstMonth="
                + firstMonth + "]";
    }

}
